<?php
class DBConnection {
	private $m_mysqli = NULL;
	
	public function Connect() {
		$password = "";
		$this -> m_mysqli = new mysqli(\DBSettings::DBHOST, \DBSettings::DBUSER, \DBSettings::DBPASSWORD, \DBSettings::DATABASE);
		//Set charset
		$this -> m_mysqli -> set_charset("utf8");

		//Check connection
		if ($this -> m_mysqli -> connect_errno) {
			echo "Connect failed: $this->m_mysqli->connect_error";
			return false;
		}
		return true;
	}

	public function Close() {
		//closes connection
		$this -> m_mysqli -> close();
	}
	/**
	 * Run prepare and handle the errormessages, prob should fix the errormessages. shouldha woulda coulda... 
	 * @return mysqli_stmt
	 */
	public function Prepare($sql) {
		if ($this -> m_mysqli == NULL) {
			throw new Exception("Du måste anropa Connect innan du anropar Prepare");
			Log::LogError('DBConnection: Prepare: Något är fel på funktionen');
		}

		$stmt = $this -> m_mysqli -> prepare($sql);

		if ($stmt === FALSE) {
			Log::LogError("Förberedelsen av '$sql' misslyckades" . $this -> m_mysqli -> error);
			return false;
		}
		return $stmt;
	}

}
